//判断是否是正数(包括小数)
function isPositiveNumber(str){
    var re =/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
    return re.test(str)
}
//判断是否是正整数（不包括小数）
function isPositiveInteger(str){
    var re =/^[+]{0,1}(\d+)$/;
    return re.test(str)
}
//检测是否为中文
function isChinese(str){
    if(/^[\u3220-\ufA29]+$/.test(str)){
        return true;
    }else {
        return false;
    }
}
//校验手机号
function isPhone(str) {
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(str)) {
        return false;
    } else {
        return true;
    }
}
//校验身份证号
function isIdCodeValid(code){
    //身份证号合法性验证
    //支持15位和18位身份证号
    //支持地址编码、出生日期、校验位验证
    var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
    var row={
        pass:true,
        msg:'验证成功'
    };
    if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/.test(code)){
        row={
            'pass':false,
            'msg':'身份证号格式错误'
        };
    }else if(!city[code.substr(0,2)]){
        row={
            'pass':false,
            'msg':'身份证号地址编码错误'
        };
    }else{
        //18位身份证需要验证最后一位校验位
        if(code.length == 18){
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
            //校验位
            var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++)
            {
                ai = code[i];
                wi = factor[i];
                sum += ai * wi;
            }
            if(parity[sum % 11] != code[17].toUpperCase()){
                row={
                    'pass':false,
                    'msg':'身份证号校验位错误'
                };
            }
        }
    }
    return row;
}


function studentInfoEntry() {
    // 新增
    var studentName = $("#wt-body input[name=studentName]").val()
    if (!studentName) {
        alert("请输入姓名。");
        return;
    }if(!isChinese(studentName)){
        alert("请输入中文姓名")
        return;
    }if (studentName.length < 2 || studentName.length > 10) {
        alert("请输入正确的姓名。");
        return;
    }
    var age = $("#wt-body input[name=age]").val()
    if (!age) {
        alert("请输入年龄。");
        return;
    }if(!isPositiveInteger(age)){
        alert("请输入正确年龄")
        return;
    }if (Number(age) < 16 || Number(age) > 40) {
        alert("请输入正确的年龄,限16-40。");
        return;
    }
    var genderNumber = $("#wt-body input[name=genderNumber]:checked").val()
    if (!genderNumber) {
        alert("请选择性别。");
        return;
    }
    var phone = $("#wt-body input[name=phone]").val()
    if (!phone) {
        alert("请输手机号。");
        return;
    }if(!isPositiveInteger(phone)){
        alert("请输入正整数")
        return;
    }if (phone.length != 11) {
        alert("请输入正确长度的手机号。仅限国内！");
        return;
    }if(!isPhone(phone)){
        alert("请输入合法手机号")
        return;
    }
    var identityNumber = $("#wt-body input[name=identityNumber]").val()
    if (!identityNumber) {
        alert("请输入身份证号。");
        return;
    }if (identityNumber.length != 18) {
        alert("请输入正确的身份证号。支持国内二代身份证18位");
        return;
    }else {
        var row=isIdCodeValid(identityNumber);
        if(row.pass==false){
            alert(row.msg);
            return;
        }
    }
    var homeAddress = $("#wt-body input[name=homeAddress]").val()
    if (!homeAddress) {
        alert("请输入家庭住址");
        return;
    }if(!isChinese(homeAddress)){
        alert("请输入中文格式家庭住址");
        return;
    }if(homeAddress.length<6||homeAddress.length>50){
        alert("请输入详细家庭住址");
        return;
    }
    var emergencyContactName = $("#wt-body input[name=emergencyContactName]").val()
    if (!emergencyContactName) {
        alert("请输入紧急联系人姓名。");
        return;
    }if(!isChinese(emergencyContactName)){
        alert("请输入紧急联系人中文姓名");
        return;
    }if (emergencyContactName.length < 2 || emergencyContactName.length > 10) {
        alert("请输入正确紧急联系人姓名。");
        return;
    }

    var emergencyContactPhone = $("#wt-body input[name=emergencyContactPhone]").val()
    if (!emergencyContactPhone) {
        alert("请输紧急联系人手机号。");
        return;
    }if(!isPositiveInteger(emergencyContactPhone)){
        alert("请输入正确格式紧急联系人手机号");
        return;
    }if (emergencyContactPhone.length != 11) {
        alert("请输入正确长度的紧急联系人手机号。仅限国内！");
        return;
    }if(!isPhone(emergencyContactPhone)){
        alert("请输入合法紧急联系人手机号");
        return;
    }
    var preVocational=$("#wt-body input[name=preVocational]").val();
    if(!preVocational){
        alert("请输入前职业");
        return;
    }if(!isChinese(preVocational)){
        alert("请输入中文前职业");
        return;
    }
    var tuitionAmount=$("#wt-body input[name=tuitionAmount]").val();
    if(!tuitionAmount){
        alert("请选择费用类型");
        return;
    }
    var discountAmount=$("#wt-body input[name=discountAmount]").val();
    if(!discountAmount){
        alert("请选择优惠信息类型");
        return;
    }
    var registeryFee = $("#wt-body input[name=registeryFee]").val();
    if (!registeryFee) {
        alert("请输入报名费,如无，请输入0");
        return;
    }
    var tuitionPaid=$("#wt-body input[name=tuitionPaid]").val();
    if(!tuitionPaid){
        alert("请输入已缴费用，如无，请输入0");
        return;
    }
    var registrationDate = $("#wt-body input[name=registrationDate]").val()
    if (!registrationDate) {
        alert("请选择报名日期");
        return;
    }
    var introducer = $("#wt-body input[name=introducer]").val()
    if (!introducer) {
        alert("请输入介绍人");
        return;
    }if(!isChinese(introducer)){
        alert("请输入中文介绍人姓名")
        return;

    }if (introducer.length < 2 || introducer.length > 10) {
        alert("请输入正确介绍人姓名。");
        return;
    }
    var remainingBed=$("#wt-body input[name=remainingBed]").val();
    if(!remainingBed){
        alert("请选择宿舍");
        return;
    }
    return true;
}

function studentInfoModify() {
    // 修改
    var studentName = $("#stu-Info-modify input[name=studentName]").val()
    if (!studentName) {
        alert("请输入姓名。");
        return;
    }if(!isChinese(studentName)){
        alert("请输入中文")
        return;
    }if (studentName.length < 2 || studentName.length > 50) {
        alert("请输入正确的姓名。");
        return;
    }
    var age = $("#stu-Info-modify input[name=age]").val()
    if (!age) {
        alert("请输入年龄。");
        return;
    }if(!isPositiveInteger(age)){
        alert("请输入正确年龄")
        return;
    }if (Number(age) < 16 || Number(age) > 40) {
        alert("请输入正确的年龄,限16-40。");
        return;
    }
    var genderNumber = $("#stu-Info-modify input[name=genderNumber]:checked").val()
    if (!genderNumber) {
        alert("请选择性别。");
        return;
    }
    var phone = $("#stu-Info-modify input[name=phone]").val()
    if (!phone) {
        alert("请输手机号。");
        return;
    }if(!isPositiveInteger(phone)){
        alert("请输入正整数");
        return;
    }if (phone.length != 11) {
        alert("请输入正确长度的手机号。仅限国内！");
        return;
    }if(!isPhone(phone)){
        alert("请输入合法手机号")
        return;
    }
    var identityNumber = $("#stu-Info-modify input[name=identityNumber]").val()
    if (!identityNumber) {
        alert("请输入身份证号。");
        return;
    }if (identityNumber.length != 18) {
        alert("请输入正确的身份证号。支持国内二代身份证18位");
        return;
    }else {
        var row=isIdCodeValid(identityNumber);
        if(row.pass==false){
            alert(row.msg);
            return;
        }
    }
    var homeAddress = $("#stu-Info-modify input[name=homeAddress]").val()
    if (!homeAddress) {
        alert("请输入家庭住址");
        return;
    }if(!isChinese(homeAddress)){
        alert("请输入中文格式家庭住址");
        return;
    }if(homeAddress.length<6||homeAddress.length>50){
        alert("请输入详细家庭住址");
        return;
    }

    var emergencyContactName = $("#stu-Info-modify input[name=emergencyContactName]").val()
    if (!emergencyContactName) {
        alert("请输入紧急联系人姓名。");
        return;
    }if(!isChinese(emergencyContactName)){
        alert("请输入紧急联系人中文姓名");
        return;
    }if (emergencyContactName.length < 2 || emergencyContactName.length > 10) {
        alert("请输入正确紧急联系人姓名。");
        return;
    }

    var emergencyContactPhone = $("#stu-Info-modify input[name=emergencyContactPhone]").val()
    if (!emergencyContactPhone) {
        alert("请输紧急联系人手机号。");
        return;
    }if(!isPositiveInteger(emergencyContactPhone)){
        alert("请输入正确紧急联系人手机号");
        return;
    }if (emergencyContactPhone.length != 11) {
        alert("请输入正确长度的紧急联系人手机号。仅限国内！");
        return;
    }if(!isPhone(emergencyContactPhone)){
        alert("请输入合法紧急联系人手机号");
        return;
    }
    var preVocational=$("#stu-Info-modify input[name=preVocational]").val();
    if(!preVocational){
        alert("请输入前职业");
        return;
    }if(!isChinese(preVocational)){
        alert("请输入中文前职业");
        return;
    }
    var tuitionAmount=$("#stu-Info-modify input[name=tuitionAmount]").val();
    if(!tuitionAmount){
        alert("请选择费用类型");
        return;
    }
    var discountAmount=$("#stu-Info-modify input[name=discountAmount]").val();
    if(!discountAmount){
        alert("请选择优惠信息类型");
        return;
    }
    var registeryFee = $("#stu-Info-modify input[name=registeryFee]").val();
    if (!registeryFee) {
        alert("请输入报名费,如无，请输入0");
        return;
    }
    var tuitionPaid=$("#stu-Info-modify input[name=tuitionPaid]").val();
    if(!tuitionPaid){
        alert("请输入已缴费用，如无，请输入0");
        return;
    }
    var registrationDate = $("#stu-Info-modify input[name=registrationDate]").val()
    if (!registrationDate) {
        alert("请选择报名日期");
        return;
    }
    var introducer = $("#stu-Info-modify input[name=introducer]").val()
    if (!introducer) {
        alert("请输入介绍人");
        return;
    }if(!isChinese(introducer)){
        alert("请输入中文介绍人姓名")
        return;

    }if (introducer.length < 2 || introducer.length > 10) {
        alert("请输入正确介绍人姓名。");
        return;
    }
    var remainingBed=$("#stu-Info-modify input[name=remainingBed]").val();
    if(!remainingBed){
        alert("请选择宿舍");
        return;
    }

    return true;
}

function relationshipInfoAdd(){
    var emergencyContactRelationship = $("#relationshipInfoAdd input[name=emergencyContactRelationship]").val()
    if(!emergencyContactRelationship){
        alert("请输入紧急联系人关系")
        return;
    }if(!isChinese(emergencyContactRelationship)){
        alert("请输入中文")
        return;
    }if(emergencyContactRelationship.length<2 ||emergencyContactRelationship.length>10 ){
        alert("请输入正确格式紧急联系人关系,文字长度2到10之间")
        return;
    }
    return true;
}

function entryTypeAdd(){
    var studentAdmissionType = $("#entryTypeAdd input[name=studentAdmissionType]").val()
    if(!studentAdmissionType){
        alert("请输入入学信息类型")
        return;
    }if(!isChinese(studentAdmissionType)){
        alert("请输入中文");
        return;
    }if(studentAdmissionType.length<2 ||studentAdmissionType.length>10 ){
        alert("请输入正确格式入学信息类型,文字长度2到10之间");
        return;
    }
    return true;
}

function educationInfoAdd(){
    var academicName = $("#educationInfoAdd input[name=academicName]").val()
    if(!academicName){
        alert("请输入学历信息类型")
        return;
    }if(!isChinese(academicName)){
        alert("请输入文字")
        return;
    }if(academicName.length<2 ||academicName.length>10 ){
        alert("请输入正确格式入学历息类型;文字长度2到10之间")
        return;
    }
    return true;
}

function termInfoAdd(){
    var semesterName = $("#termInfoAdd input[name=semesterName]").val()
    if(!semesterName){
        alert("请输入中文学期")
        return;
    }if(!isChinese(semesterName)){
        alert("请输入文字")
        return;

    }if(semesterName.length<3 ||semesterName.length>10 ){
        alert("请输入正确格式中文学期;文字长度3到10之间");
        return;
    }
    var startDate = $("#termInfoAdd input[name=startDate]").val()
    if(!startDate){
        alert("请输入开学时间")
        return;
    }
    return true;
}

function dormitoryInfoAdd(){
    var dormitoryNumber = $("#dormitoryInfoAdd input[name=dormitoryNumber]").val()
    if(!dormitoryNumber){
        alert("请输入宿舍号")
        return;
    }if(dormitoryNumber.length<5 ||dormitoryNumber.length>50 ){
        alert("请输入标准格式宿舍号")
        return;
    }
    var totalBed = $("#dormitoryInfoAdd input[name=totalBed]").val()
    if(!totalBed){
        alert("请输入总共床位数")
        return;
    }if(isPositiveInteger(totalBed)==false){
        alert("提示：床位数只能用正整数表示")
        return;
    }if(Number(totalBed)<6 ||Number(totalBed)>12 ){
        alert("请输入指定范围床位数")
        return;
    }
    var genderNumber=$("#dormitoryInfoAdd input[name=genderNumber]:checked").val()
    if(!genderNumber){
        alert("请选择性别")
        return;
    }
    var roomPassword = $("#dormitoryInfoAdd input[name=roomPassword]").val()
    if(!roomPassword){
        alert("请输入宿舍密码")
        return;
    }if(roomPassword.length<6 ||roomPassword.length>12 ){
        alert("请输入正确宿舍密码")
        return;
    }
    return true;
}

function costInfoAdd(){
    var stuTuitionName = $("#costInfoAdd input[name=stuTuitionName]").val()
    if(!stuTuitionName){
        alert("请输入费用名称")
        return;
    }if(stuTuitionName.length<6 ||stuTuitionName.length>50 ){
        alert("请输入长度符合的费用名称")
        return;
    }
    var stuTuitionAmount = $("#costInfoAdd input[name=stuTuitionAmount]").val()
    if(!stuTuitionAmount){
        alert("请输入费用金额")
        return;
    }if(isPositiveNumber(stuTuitionAmount)==false ){
        alert("请输入正确费用金额");
        return;
    }
    var tuitionDescription = $("#costInfoAdd input[name=tuitionDescription]").val()
    if(!tuitionDescription){
        alert("请输入描述")
        return;
    }if(tuitionDescription.length>50){
        alert("描述长度超出输入限制")
        return;
    }
    return true;
}

function discountInfoAdd(){
    var discountInfName = $("#discountInfoAdd input[name=discountInfName]").val()
    if(!discountInfName){
        alert("请输入优惠信息名称")
        return;
    }if(discountInfName.length<6 ||discountInfName.length>50 ){
        alert("请输入长度符合的优惠信息名称")
        return;
    }
    var addDiscountAmount = $("#discountInfoAdd input[name=addDiscountAmount]").val()
    if(!addDiscountAmount){
        alert("请输入优惠金额")
        return;
    }if(isPositiveNumber(addDiscountAmount)==false ){
        alert("请输入正确优惠金额");
        return;
    }
    var discountDescription = $("#discountInfoAdd input[name=discountDescription]").val()
    if(!discountDescription){
        alert("请输入描述")
        return;
    }if(discountDescription.length>50){
        alert("描述长度超出输入限制")
        return;
    }
    return true;
}

function userAdd(){
    var username = $("#userAdd #username").val()
    if(!username){
        alert("请输入用户名")
        return;
    }if(username.length<6 ||username.length>50 ){
        alert("请输入正确用户名")
        return;
    }
    var password = $("#userAdd #password").val()
    if(!password){
        alert("请输入密码")
        return;
    }if(password.length<6 ||password.length>32  ){
        alert("请输入正确密码")
        return;
    }
    var userphone = $("#userAdd #userphone").val()
    if (!userphone) {
        alert("请输手机号。");
        return;
    }if(!isPositiveInteger(userphone)){
        alert("请输入正整数");
        return;
    }if (userphone.length != 11) {
        alert("请输入正确长度的手机号。仅限国内！");
        return;
    }if(!isPhone(userphone)){
        alert("请输入合法手机号");
        return;
    }
    return true;
}

function updatePwd(){
    var oldPassWord = $("#updatePwd #oldPassWord").val()
    if(!oldPassWord){
        alert("请输入密码")
        return;
    }if(oldPassWord.length<6 ||oldPassWord.length>18  ){
        alert("请输入正确密码")
        return;
    }
    var newPassWord = $("#updatePwd #newPassWord").val()
    if(!newPassWord){
        alert("请输入密码")
    }if(newPassWord.length<6 ||newPassWord.length>18  ){
        alert("请输入正确密码")
        return;
    }

    return true;

}
